package com.asia5b.a5mall.shop.fragment

import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.asia5b.a5mall.middleware.base.SimpleFragment
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.shop.ShopCategoryModel
import com.asia5b.a5mall.shop.activity.ShopCategoryActivity
import com.asia5b.a5mall.shop.adapter.ShopCategoryAdapter
import com.asia5b.a5mall.shop.databinding.FragmentShopcategoryBinding
import kotlinx.android.synthetic.main.fragment_shopcategory.*

/**
 * Created by zhangyuncai on 2020/4/23.
 * 店铺分类
 */
class ShopCategoryFragment : SimpleFragment<SimpleViewModel, FragmentShopcategoryBinding>() {
    override val viewModelClazz: Class<SimpleViewModel>
        get() = SimpleViewModel::class.java

    override fun getDataBinding(container: ViewGroup?): FragmentShopcategoryBinding {
        return FragmentShopcategoryBinding.inflate(layoutInflater,container,false)
    }
    var shopId = 0
    val mRecyclerView by lazy { rv_shopcategory }
    val mDatas = arrayListOf<ShopCategoryModel>()
    val mAdapter by lazy { ShopCategoryAdapter(mDatas) }

    override fun initView() {
        mRecyclerView.run {
            layoutManager = LinearLayoutManager(mActivity)
            adapter = mAdapter
        }
        mAdapter.setOnItemClickListener { adapter, view, position ->
            var shopCategoryActivity=mActivity as ShopCategoryActivity
            val item = mAdapter.getItem(position)!!
            if (item.child.isNullOrEmpty()) {
                shopCategoryActivity.pushActivity(item)
            } else {
                shopCategoryActivity.pushFragment(item.child!!)
            }
        }
    }

    override fun initEvent() {
    }

    override fun lazyFetchData() {
    }


}